

import 'package:dio/dio.dart';
import 'package:libflutter/Contact.dart';

/// Token拦截器
class CommonInterceptors extends InterceptorsWrapper {
  final String ibsaasLanguage;
  final String v;

  CommonInterceptors(this.ibsaasLanguage, this.v);

  @override
  onRequest(RequestOptions options, handler) async {
    try {
      options.headers["loginType"] = Contact.deviceType;
      options.headers["ibsaasLanguage"] = ibsaasLanguage;
      options.headers["v"] = v;

      options.headers["Content-Type"] ??= 'application/json';
      options.connectTimeout ??= const Duration(milliseconds: 30000);
      options.sendTimeout ??= const Duration(milliseconds: 30000);
      options.receiveTimeout ??= const Duration(milliseconds: 30000);
    } catch (e) {
      print("CommonInterceptors ${e}");
    }
    return super.onRequest(options, handler);
  }
}
